package org.anupta.realm.server.realm.client;

import org.anupta.realm.entity.entities.Account;
import org.anupta.realm.server.realm.packet.login.HelloConnection;
import org.anupta.realm.utils.others.Utils;
import org.apache.mina.core.session.IoSession;

public class RealmClient {
	public enum State {
		VERSION,
		LOGIN,
		GAMESERVER
	}
	
	private IoSession session = null;
	private RealmParser parser = null;
	private State state = State.VERSION;
	private String hash = null;
	private Account account = null;
	
	public RealmClient(IoSession session){
		setSession(session);
		setHash(Utils.getRandomString(32).toString());
		parser = new RealmParser(this,hash);
		new HelloConnection(this,hash);
	}
	
	public void parsePacket(String message){
		parser.parse(message);
	}
	
	public void timeOut(){
		session.close(true);
	}
	
	public void quit(){
		session.close(true);
	}
	
	public void send(String message){
		if(!message.isEmpty() || !(message == null)){
			session.write(message);
		}
	}

	public State getState() {
		return state;
	}

	public void setState(State state) {
		this.state = state;
	}
	
	public String getIp(){
		return session.getRemoteAddress().toString();
	}

	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}
	
	private void setSession(IoSession session){
		this.session = session;
	}
	
	public String getHash(){
		return hash;
	}
	
	private void setHash(String hash){
		this.hash = hash;
	}
}
